package com.lb.jwitter.action;


 import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import java.util.Map; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblThongTinNhomLopMonHoc;
import com.lb.jwitter.service.TblThongTinNhomLopMonHocService;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblThongTinTKB;
import com.lb.jwitter.service.TblThongTinTKBService;

import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblThongTinNhomLopMonHocFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Collection<TblThongTinNhomLopMonHoc> tblThongTinNhomLopMonHocs; 
    public Collection<TblThongTinNhomLopMonHoc>  getTblThongTinNhomLopMonHocs() {
         return tblThongTinNhomLopMonHocs; 
      } 

    private TblThongTinNhomLopMonHocService tblThongTinNhomLopMonHocService; 

    private List<TblDKMHDotDK> tblDKMHDotDKs; 

    public List<TblDKMHDotDK> getTblDKMHDotDKs() {
		return tblDKMHDotDKs;
	}

	public void setTblDKMHDotDKs(List<TblDKMHDotDK> tblDKMHDotDKs) {
		this.tblDKMHDotDKs = tblDKMHDotDKs;
	}

	private TblDKMHDotDKService tblDKMHDotDKService; 

    private Collection<TblCTDTMonHoc> tblCTDTMonHocs; 
    public Collection<TblCTDTMonHoc>  getTblCTDTMonHocs(){ 
              return tblCTDTMonHocs; 
     } 

    private TblCTDTMonHocService tblCTDTMonHocService; 

    private Collection<TblThongTinTKB> tblThongTinTKBs; 
    public Collection<TblThongTinTKB>  getTblThongTinTKBs(){ 
              return tblThongTinTKBs; 
     } 

    private TblThongTinTKBService tblThongTinTKBService; 

    private Collection<TblCanBo> tblCanBos; 
    public Collection<TblCanBo>  getTblCanBos(){ 
              return tblCanBos; 
     } 

    private TblCanBoService tblCanBoService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_ThongTin_NhomLop_MonHoc", "xem")){ 
        return "noprivilege"; 
    }tblThongTinNhomLopMonHocService = (TblThongTinNhomLopMonHocService) context.getBean("tbl_ThongTin_NhomLop_MonHocClient"); 
         tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient"); 

        tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient"); 

        tblThongTinTKBService = (TblThongTinTKBService) context.getBean("tbl_ThongTin_TKBClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 

       if(pageSize == 0){ 
            pageSize = 20; 
        } 
        if(page == 0){ 
            page =1; 
        } 
        List<ConditionReport> cons = new ArrayList<ConditionReport>();
        { 
            ConditionReport con = new ConditionReport(); 
            con.setCol("id"); 
            con.setValue1("desc"); 
            con.setOperator("order"); 
            cons.add(con); 
        } 
        tblDKMHDotDKs = tblDKMHDotDKService.findtblDKMHDotDKByCondition(cons, 20, 1);
        
        cons.clear();

        if(tblDKMHDotDKs != null && tblDKMHDotDKs.size() > 0){ 
            ConditionReport con = new ConditionReport(); 
            con.setCol("dotDKId.id"); 
            con.setValue1(tblDKMHDotDKs.get(0)); 
            con.setOperator("order"); 
            cons.add(con); 
        }
        { 
            ConditionReport con = new ConditionReport(); 
            con.setCol("ma"); 
            con.setValue1("asc"); 
            con.setOperator("order"); 
            cons.add(con); 
        }
        
//        tblThongTinNhomLopMonHocs =        tblThongTinNhomLopMonHocService.findtblThongTinNhomLopMonHocByCondition(cons, pageSize, page); 
        
//        pages = tblThongTinNhomLopMonHocService.counttblThongTinNhomLopMonHocByCondition(cons)/pageSize + 1; 
      
        
        dataString = ""; 
      dataString += "&ma="; 

      if(tblDKMHDotDKs != null && tblDKMHDotDKs.size() > 0)
    	  dataString += "&dotDKId=" + tblDKMHDotDKs.get(0).getId() ; 
      dataString += "&monHocId=" ;
      
     
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi Form tbl_ThongTin_NhomLop_MonHoc Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
